package com.morgan.basemodule.holder

import android.content.Context
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.util.getItemView
import com.drakeet.multitype.ItemViewDelegate

/**
 *description：
 *<br>author：caowugao
 *<br>time：2021/2/26 0026 17:36
 */
open class MultiBindingViewDelegate<DATA, BINDING : ViewDataBinding>(@LayoutRes private val layoutResId: Int, private val dataVariableId : Int, private val positionVariableId : Int) : ItemViewDelegate<DATA, BindingHolder<BINDING>>() {

    constructor(@LayoutRes layoutResId: Int, dataVariableId : Int) : this(layoutResId, dataVariableId, -1){}

    override fun onCreateViewHolder(context: Context, parent: ViewGroup): BindingHolder<BINDING> = BindingHolder(parent.getItemView(layoutResId))

    override fun onBindViewHolder(holder: BindingHolder<BINDING>, item: DATA) {
        holder.bindData(dataVariableId, item, positionVariableId == -1)
        holder.bindData(positionVariableId, holder.adapterPosition, true)
    }
}